/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Control;

import DAO.SongJpaController;
import DAO.exceptions.NonexistentEntityException;
import DAO.exceptions.PreexistingEntityException;
import Entidad.Song;
import grlu.Main;

/**
 *
 * @author USUARIO
 */
public class SongControl {
    private SongJpaController JPASong;
    
    public SongControl(){
        JPASong = new SongJpaController(Main.emf);
    }
        
    
    public Song findSong(String name){
        return JPASong.findSong(name);
    }    
    
    
    public int deleteSong(Song song){
        try {
            JPASong.destroy(song.getTitle());
        } catch (NonexistentEntityException ex) {
            return 1;
        }
        return 0;
    }
    
    public int createSoundTrack(Song song){
        try {
            JPASong.create(song);
        } catch (PreexistingEntityException ex) {
            return 2;
        } catch (Exception ex) {
            return 1;
        }
        return 0;
    }
    
}
